document.addEventListener("DOMContentLoaded", function() {
    const slides = document.querySelectorAll(".slide");
    const loginInfo = document.querySelector(".login-info");

    let currentSlide = 0;

    function showSlide(index) {
        slides.forEach((slide) => slide.classList.remove("active"));
        loginInfo.style.display = "none";

        slides[index].classList.add("active");
        loginInfo.style.display = "block";
    }

    function nextSlide() {
        currentSlide = (currentSlide + 1) % slides.length;
        showSlide(currentSlide);
    }

    showSlide(currentSlide);

    let slideshowInterval = setInterval(nextSlide, 2000);


    slides.forEach(slide => {
        slide.addEventListener('mouseenter', () => clearInterval(slideshowInterval));
        slide.addEventListener('mouseleave', () => {
            clearInterval(slideshowInterval);
            slideshowInterval = setInterval(nextSlide, 2000);
        });
    });
});

function redirectToLogin() {
    window.location.href = "http://localhost:5173/login";
}

// 返回顶部按钮显示与隐藏
const button = document.querySelector('.back-to-top');

window.addEventListener('scroll', function () {
    if (window.scrollY > 100) {
        button.style.display = 'block'; // 页面滚动超过100px时显示按钮
    } else {
        button.style.display = 'none'; // 否则隐藏按钮
    }
});

// 回到顶部按钮点击事件
function scrollToTop() {
    window.scrollTo({
        top: 0, // 滚动到页面顶部
        behavior: 'smooth' // 平滑滚动效果
    });
}